<?php
/**
 * 
 * ClientEngage: ClientEngage Visitor Voice (http://www.clientengage.com)
 * Copyright 2012, ClientEngage (http://www.clientengage.com)
 *
 * You must have purchased a valid license from CodeCanyon in order to have 
 * the permission to use this file.
 * 
 * You may only use this file according to the respective licensing terms 
 * you agreed to when purchasing this item on CodeCanyon.
 * 
 * 
 * 
 *
 * @author          ClientEngage <contact@clientengage.com>
 * @copyright       Copyright 2013, ClientEngage (http://www.clientengage.com)
 * @link            http://www.clientengage.com ClientEngage
 * @since           ClientEngage - Visitor Voice v 1.0
 * 
 */
?>
<?php
echo $this->Html->scriptBlock('

var originalCount = ' . $pendingCount . ';

$(function(){
    $(".btn_process").on("click", function(e) {
        e.preventDefault();
        processPending();
        $(this).hide();
        $(".progress_container").fadeIn();
    });
});   

function processPending()
{
        $.ajax({
            url: "' . Router::url(array('action' => 'process_responsecache', $visitorform_id)) . '",
            type: "put",
            dataType: "json",
            success: function(data) {
                if(data.remaining > 0)
                 {
                    processPending();
                 }
                 else
                 {
                    $(".progress_container").hide();
                    $(".actionbutton_container").fadeIn();
                 }
                 var percentageComplete = ((data.remaining / originalCount) * 100);
                 $(".pending_count").text(data.remaining);
                 $(".progressbar").css("width", percentageComplete + "%");
            }
        });    
}

');
?>

<div class="visitorvoices view row">
    <div class="actions span2">

    </div>
    <div class="span10">
        <h2><?php echo __('Re-Generate Response Cache'); ?></h2>
        <p>
            <?php echo __('Outstanding Response Cache Objects'); ?>: 
            <span class="pending_count"><?php echo $pendingCount; ?></span>
        </p>
        <?php if ($pendingCount > 0): ?>
            <?php
            echo $this->Html->link(__('Start Processing'), '#', array('class' => 'btn btn-primary btn_process'));
            ?>
        <?php endif; ?>
        <div class="row-fluid progress_container" style="display: none;">
            <div class="span1">
                <?php echo $this->Html->image('common/loading.gif', array('class' => 'img_loading pull-right')); ?>
            </div>
            <div class="span11">
                <div class="progress progress-striped active">
                    <div class="bar progressbar" style="width: <?php echo $pendingCount == 0 ? '0' : '100'; ?>%;"></div>
                </div>
            </div>
        </div>
        <div class="row-fluid actionbutton_container" style="<?php echo $pendingCount > 0 ? 'display: none;' : ''; ?>">
            <div class="span12">
                <div class="btn-group">
                    <?php
                    echo $this->Html->link('<i class="ico-chart_curve"></i> ' . __('View Statistics'), array('action' => 'statistics', $visitorform_id), array('class' => 'btn btn-primary', 'escape' => false));
                    echo $this->Html->link('<i class="ico-table"></i> ' . __('Response List'), array('action' => 'responses', $visitorform_id), array('class' => 'btn btn-primary', 'escape' => false));
                    echo $this->Html->link('<i class="ico-page_white_excel"></i> ' . __('Export Responses'), array('action' => 'export', $visitorform_id), array('class' => 'btn btn-primary', 'escape' => false));
                    ?>
                </div> 
            </div> 
        </div>
    </div>
</div>